﻿using ConfExpert.Forms.Base;
using DevExpress.Utils;
using DevExpress.XtraEditors.Repository;
using DevTeam;

using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;

namespace ConfExpert.Forms.SatinAlma.YeniYapi
{
    public partial class AyrimTalep2 : XForm
    {
        int POId = 0;
        public AyrimTalep2(int POId)
        {
            InitializeComponent();
            this.POId = POId;
        }

        private void AyrimTalep2_Load(object sender, EventArgs e)
        {
            //gridview2 de ETA'yı da göster. Gelen kumaşı listeden çıkar!

            Fill();

            //btnKaydet.ItemClick += btnKaydet_ItemClick;
            //chkShowOnly.CheckedChanged += chkShowOnly_CheckedChanged;

            if (isKD)
            {
                //GridManager gm = GridManager.GetManager(gridView1);
                //gm.GridMenu.AddMenu("Bu ayrımı böl", Bol);

                DataTable t = ExecuteDataTable("GetAktifSiparisler");
                List<int> sip = new List<int>();
                foreach (DataRow r in t.Rows)
                    sip.Add(r["POId"].ToInt());

                ((RepositoryItemComboBox)cmbPOId.Edit).Items.AddRange(sip);
                ((RepositoryItemComboBox)cmbPOId.Edit).TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
                cmbPOId.EditValue = POId;
                cmbPOId.EditValueChanged += cmbPOId_EditValueChanged;                
            }
            else
            {
                //bs1.Filter = "MyCust>0 OR Durum = 'Yeni'";
                gridView1.BestFitColumns();
                cmbPOId.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            }

            cmbPOId.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;

            //gridView1_FocusedRowChanged(null, null);
            splitContainerControl1.AutoSize();
            gridView1.FocusedRowChanged += gridView1_FocusedRowChanged;
            gridView1.RowCellStyle+=gridView1_RowCellStyle;
        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gridView2.BestFitColumns();
        }

        void cmbPOId_EditValueChanged(object sender, EventArgs e)
        {
            POId = cmbPOId.EditValue.ToInt();
            Fill();
        }

        private void Fill()
        {
            this.Text = "AyrimTalep2- " + POId.ToStr();
            gridView1.Init("GetPOAyrim2", POId, BolunecekAyrimId, WhoAmI);
            gridView1.AddDetailGrid(gridView2, "POLinesId");

            //gleBolunecekAyrim.Edit.Assign(GetCustomGLE(gridView1.DataTable(), "AyrimId", "AyrimId"));
            //((RepositoryItemGridLookUpEdit)gleBolunecekAyrim.Edit).View.Columns["AyrimId"].ColumnEdit = RI(Rp.Ayrim);

            gridView1.FormatAsNumber(1, "OrderedQty", "BolunecekQty", "NewQty");
            gridView1.AddSummary("OrderedQty", "BolunecekQty", "NewQty");
            //gridView1.Columns["AyrimId"].SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
            gridView2.FormatAsNumber(1, "Qty");
            gridView2.AddSummary("Qty");

            gridView1.MakeColumnInvisible("ProductId", "POLinesId", "AyrimlarId", "NewQty");
            gridView2.MakeColumnInvisible("AyrimlarId", "OnayBekliyor");
            //gridView1.FocusedRowChanged += gridView1_FocusedRowChanged;
            gridView1.MoveFirst();

            gridView1.MakeReadOnly();
            gridView2.MakeReadOnly();

            gridView1.BestFitColumns();
            gridView2.BestFitColumns();
        }

        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.RowHandle > -1)
                if (e.Column.FieldName == "OrderedQty")
                        e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
        }

        int BolunecekAyrimId = 7860;
       
    }
}
